app
.controller('YsModalRadioCtrl', ['$scope', '$http', YsModalRadioController]);
function YsModalRadioController($scope, $http){

	$scope.radio.selectedIndex = -1; // 当前选中的行码，-1代表未选中，隐藏后需要重新赋值为-1

	var gridId = $scope.gridId;
	$scope.radio.doubleClick = function(data) {
		console.log('---------$scope.radio.code--------------', $scope.radio.code);
		
		$scope.radio.doSelected(data);
	}
	$scope.radio.singleClick = function(data, index) {
		$scope.radio.selectedIndex = index;
		for (var i = 0; i < $scope.radio.rows.length; i++) {
			$scope.radio.rows[i]['ys_sub_grid_radio'] = false;
		}
		$scope.radio.rows[index]['ys_sub_grid_radio'] = true;
	}
	
	/*
	 * 单选框确认选中
	 */
	$scope.radio.confirm = function() {
		if($scope.radio.selectedIndex < 0) {
			layer.msg('请选择一条数据');
			return;
		} else {
			var data = $scope.radio.rows[$scope.radio.selectedIndex];
			$scope.radio.doSelected(data);
		}
		console.log('-----selectedIndex-----', $scope.radio.selectedIndex);
		if (gridId) {
			
		}
	}
	$scope.radio.doSelected = function(data) {
		if($scope.radio.type == 1) { // 表单用
			for(var i = 0; i < $scope.rows.length; i++) {
				var row = $scope.rows[i];
				if(row.code == $scope.radio.code) {
					$scope.valueMap[row.code] = data[row.modalValueCode];
				} else if(row.modalRelativeCode == $scope.radio.code) {
					$scope.valueMap[row.code] = data[row.modalValueCode];
				}
				$scope.changeValueMap(row.code);
			}
		} else if($scope.radio.type == 2) { // 子列表用
			var subIndex = $scope.radio.subIndex;
			for(var i = 0; i < $scope.subGrid.colGridArr.length; i++) {
				var col = $scope.subGrid.colGridArr[i];
				if(col.field == $scope.radio.code) {
					$scope.subGrid.sonlist[subIndex][col.field] = data[col.modalValueCode];
				} else if(col.modalRelativeCode == $scope.radio.code) {
					$scope.subGrid.sonlist[subIndex][col.field] = data[col.modalValueCode];
				}
			}
		} else if($scope.radio.type == 3) { // 特殊调用
			$scope.doSelectRadioBySelf(data);
		}
		
		$scope.radio.bsObj.hide();
		$scope.radio.selectedIndex = -1; // 当前选中的行码清空
	}
}